package cs2340.flyingkiwi.todoapp;

import java.util.ArrayList;
import java.util.List;

import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


/**
 * KiWiMaps class
 * Create google map.
 * @author Group Flying Kiwi
 * @version 1 April 2012
 */
public class KiWiMaps extends MapActivity{
	 
	 private ToDoAppDbAdapter mDbHelper;

	 protected boolean isRouteDisplayed() {
		 return false;
	 }
	 public void onCreate(Bundle savedInstanceState) {

		 super.onCreate(savedInstanceState);
		 setContentView(R.layout.map);
		 MapView mapView = (MapView) findViewById(R.id.mapview);
		 mapView.setBuiltInZoomControls(true);
		 
		 List<Overlay> mapOverlays = mapView.getOverlays();
		 Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
		 KiwiItemizedOverlay itemizedoverlay = new KiwiItemizedOverlay(drawable, this);
		 
		 mDbHelper = new ToDoAppDbAdapter(this);
		 mDbHelper.open();
		 ArrayList<GeoPoint> geoPoints = new ArrayList<GeoPoint>();
		 ArrayList<OverlayItem> overlayItems = new ArrayList<OverlayItem>();
		 
		 Cursor itemCursor = mDbHelper.fetchAllItems();
		 itemCursor.moveToFirst();
		 int i = 0;
		 
		 while(!itemCursor.isAfterLast()){
			 geoPoints.add(new GeoPoint(Integer.parseInt(itemCursor.getString(3).split(" ")[0]) , Integer.parseInt(itemCursor.getString(3).split(" ")[1])));
			 overlayItems.add(new OverlayItem(geoPoints.get(i), "aaaaaa", "aaaaaa"));
			 itemizedoverlay.addOverlay(overlayItems.get(i));
			 
			 itemCursor.moveToNext();
			 i++;
			 
		 }
		 mapOverlays.add(itemizedoverlay);

	 }
}




